//类型定义
import type { SunAdminOptions } from "./types";
//store
import { useStartLoadingStore } from "./stores/startLoading";
//css
import "./assets/main.css";

//安装
import { setupRouter,router } from "./router";
import pinia from "./stores";
import { apiConfig } from "./utils/config";
import { components as commonComponents } from "./components/common";
import { updateAxiosConfig } from "./utils/request";
import { wsManager } from "./utils/wsManager";

const SunAdmin = {
    install: (app, options: SunAdminOptions) => {
        //配置 API 基础地址（最高优先级）
        Object.assign(apiConfig, options.apiConfig);
        updateAxiosConfig();

        // 2. 注册全局组件
        commonComponents.forEach((c) => {
            app.component(c.name, c);
        });

        //安装路由
        const router = setupRouter(options.basePath);
        options.routes.forEach((route) => {
            if (route.meta?.outside) {
                router.addRoute(route);
            } else {
                router.addRoute("sunadmin-layout", route);
            }
        });
        app.use(router);

        //安装pinia
        app.use(pinia);

        // 启动系统初始化（延迟执行确保所有组件都已准备就绪）
        setTimeout(() => {
            useStartLoadingStore().initializeSystem();
        }, 100);
    },
};
import { formatTimestamp, formatFriendlyTime } from "./utils/date";
export { formatTimestamp, formatFriendlyTime };
import * as request from "./utils/request";
import version from "./assets/version.json";
export { SunAdmin, router, pinia, request, wsManager, useStartLoadingStore,version };
